﻿using Microsoft.AspNetCore.Mvc;

namespace ControllerT.Controllers
{
    public class MyController : Controller
    {

        public IActionResult Index2()
        {
            return View();
        }
        public string Welcome()
        {
            return "Welcome Controller ！！！！";
        }

        // 返回内容
        public IActionResult GetContent()
        {
            return Content("Hello, World!");
        }

        // 返回文件
        public IActionResult DownloadFile()
        {
            byte[] fileBytes = System.IO.File.ReadAllBytes("DownloadFiles/2.pdf");
            return File(fileBytes, "application/pdf", "document.pdf");
        }

        // 重定向
        public IActionResult RedirectToHome()
        {
            return RedirectToAction("Index", "Home");
        }

        // 返回状态码
        public IActionResult NotFoundResult()
        {
            return NotFound();
        }

        public IActionResult BadRequestResult()
        {
            return BadRequest("Invalid request");
        }

        // 返回 JSON 数据
        public IActionResult GetJson()
        {
            var product = new { Id = 1, Name = "Laptop", Price = 999.99m };
            return Json(product);
        }
    }
}
